import { Injectable } from '@angular/core';
import { BaseService } from '@core/routes-services/base.service';
import { CacheService } from '@core/routes-services/cache.service';
import { HttpClient } from '@angular/common/http';

/**
 * otc店铺品牌 服务
 */
@Injectable()
export class OtcShopBrandService extends BaseService {

  constructor(http: HttpClient, cacheService: CacheService) {
    super(http, cacheService);
  }

  base_url: any = 'api/otcShopBrand';


  /**
   * 分页
   *
   * @param user
   * @returns {Promise<any>}
   */
  pagination(page: any, keyword: any, status: any, centerId: any): Promise<any> {
    const url = this.base_url + '/pagination';
    if (keyword) {
      page['_filter_like_name'] = keyword;
    }
    if (status) {
      page['_filter_eq_status'] = status;
    }
    if (centerId) {
      page['_filter_eq_centerId'] = centerId;
    }
    page['_sort_by_'] = 'saveTime_desc';
    return this.post(url, page);
  }

  /**
   * 所有分页 根据 code 排重
   *
   * @param user
   * @returns {Promise<any>}
   */
  allPagination(page: any, keyword: any): Promise<any> {
    const url = this.base_url + '/all/pagination';
    if (keyword) {
      page['_filter_like_name'] = keyword;
    }
    return this.post(url, page);
  }

  /**
   * 修改
   *
   * @param id
   * @param entity
   * @returns {Promise<any>}
   */
  saveOrUpdateEntity(id: any, entity: any): Promise<any> {
    if (id) {
      const url = this.base_url + '/' + id;
      return this.put(url, entity);
    } else {
      const url = this.base_url;
      //后台管理新增的店铺默认审核通过
      entity.auditingStatus = 3;
      return this.post(url, entity);
    }
  }

  /**
   * 根据级别id获取全部
   *
   * @returns {Promise<any>}
   */
  getAll(): Promise<any> {
    const url = this.base_url + '/all';
    return this.get(url);
  }

  /**
   * 获取查看详情
   *
   * @param id
   * @returns {Promise<any>}
   */
  detail(id: any): Promise<any> {
    const url = this.base_url + '/' + id;
    return this.get(url);
  }

  /**
   * 修改
   *
   * @param id
   * @param status
   * @returns {Promise<any>}
   */
  auditing(id: any, status: any): Promise<any> {
    const url = this.base_url + '/auditing/' + id + '/' + status;
    return this.put(url, {});
  }

}
